/*
 * @title: 全局的vuex配置文件
 * @author: andy.ten@tom.com & xukaixing@hotmail.com
 * @Date: 2022-03-19 19:22:28
 * @LastEditors: andy.ten@tom.com
 * @LastEditTime: 2022-03-23 17:17:33
 * @version: 1.0.1
 * @copyright: copyright (c) 2022 andyten
 *  node: you can not copy and/or use and/or modify this program free,
 *  please reserve the segment above.Please mail me if you have any question.
 */
import Vue from 'vue';
import Vuex from 'vuex';
import getters from './getters';

Vue.use(Vuex);

// 定义目标目录下的require对象
const modulesFiles = require.context('./modules', true, /\.js$/);
const modules = modulesFiles.keys().reduce((modules, modulePath) => {
  // console.log(modulePath); // => ./user.js
  const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, '$1');
  // console.log(moduleName); // => user
  const value = modulesFiles(modulePath); // 相当于 require('./user.js');
  modules[moduleName] = value.default;
  return modules;
}, {});

const store = new Vuex.Store({
  modules,
  getters
});

export default store;
